// pages/myBalance/myBalance.js
var common = require("../../utils/Conmon.js");
var appData = getApp().globalData;
Page({

  /**
   * 页面的初始数据
   */
  data: {
     Type:1, 
     CurrencyImageUrl:'',
     NowAmount:0,
     KindName:'',
     Title:'我的余额',
     CssPlay:'block'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    common.pageInit(function () {
    });
    //区分币种类型
    var _type= options.typeId;
    var that=this;
    if (_type != null && _type!=undefined)
    {
      that.setData({
        Type: _type
      })
    }
    wx.showLoading({ title: '加载中...', mask: true });
    that.LoadExchangeSet();

    wx.request({
      url: appData.apiurl+'member/api/MemberCenter/GetUserCurrencyByType',
      method:'GET',
      data: { custId: appData.custID, userId: wx.getStorageSync('UserInfo').UserID, typeId: that.data.Type},
      header: {
        "content-type": "application/json",
        'X_ManuName': appData.manuName
      },
      success: function (res) {
        if (res.statusCode == 200 && res.data.code == 1200) {
          wx.hideLoading()
          var data = res.data;
          if (data.content!=null){
            that.setData({
              KindName: data.content.CurrencyNameSet.KindName,
              Title: '我的' + data.content.CurrencyNameSet.KindName,
              CurrencyImageUrl: data.content.CurrencyNameSet.CurrencyImageUrl,
              NowAmount: (data.content.NowAmount + data.content.LiveAmount).toFixed(2),
            })
          }
          console.log(res.data)
        }else{
          wx.hideLoading()
          wx.showModal({ title: '错误', content: res.data.msg, showCancel: false })
        }
        wx.setNavigationBarTitle({ title: that.data.Title});  //修改title
      },
      fail: function (res) {
        wx.hideLoading()
        wx.showModal({ title: '错误', content: '加载异常错误...', showCancel: false })
        console.log(res.data)
      }
    })
  },

 /**
  * 加载兑换设置
  */
  LoadExchangeSet:function(){
     var that=this;
     var _cssPlay = that.data.CssPlay;
     wx.request({
       url: appData.apiurl + 'member/api/Exchangere/GetExchangereSetList',
       method: 'GET',
       data: { custId: appData.custID, currId: that.data.Type },
       header: {
         "content-type": "application/json",
         'X_ManuName': appData.manuName
       },
       success: function (res) {
         if (res.statusCode == 200 && res.data.code == 1200) {
           if (res.data.content == null || res.data.content.length <= 0)
             _cssPlay ='none';
         }else{
           _cssPlay = 'none';
         }
         that.setData({
           CssPlay: _cssPlay
         })
       },
       fail: function (res) {
         _cssPlay = 'none';
         that.setData({
           CssPlay: _cssPlay
         })
         wx.showModal({ title: '错误', content: '加载异常错误...', showCancel: false })
         console.log(res.data)
       }
     })
     
  },
  
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})